home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 01 / bufset.c < prev    next >
Text File  |  1990-10-31  |  953b  |  35 lines

  1. /* _bufset.c -- Listing 2. */
  2.  
  3. #include <stdlib.h>
  4. #include "textbuf.h"
  5.  
  6. /* You can't use the standard memset() and memmove() functions for
  7.  * buffers because they may have been allocated from the far heap.
  8.  * The bufset() and bufmove() calls are mapped to memset() and
  9.  * memmove() when NEAR_HEAP is true, otherwise they are mapped to
  10.  * calls to the following, equivalent, far-pointer functions. Bufset
  11.  * is made a function, even though it's short enough for a macro,
  12.  * to avoid side effects on "size" and "p."
  13.  */
  14.  
  15. void _bufset( bufptr p, const int c, bufsize size )
  16. {
  17.     while( size-- > 0 )         /* Assume size can be unsigned */
  18.         *p++ = c;
  19. }
  20.  
  21. void _bufmove( bufptr dst, bufptr src, bufsize size )
  22. {
  23.     if( dst < src )
  24.         while( size-- > 0 )
  25.             *dst++ = *src++ ;
  26.     else
  27.     {
  28.         dst += size;
  29.         src += size;
  30.         while( size-- > 0 )
  31.             *--dst = *--src;
  32.     }
  33. }
  34.  
  35.